<?php

namespace App\Http\Controllers\Saas;

use App\Contract\ContractStatus;
use App\Http\Controllers\Controller;
use App\Http\Resources\PaginationCollection;
use App\Model\Agent;
use App\Model\Business;
use App\Model\CashDisabled;
use App\Model\Device;
use App\Model\UserBlack;
use App\Model\UserCashLog;
use App\User;
use App\Utils\Result;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;

class DisabledController extends Controller
{

    public function edit(Request $request){
        $id = $request->input('id');
        $status = $request->input('status');
        $user = CashDisabled::query()->where('id',$id)->first();
        $user->status = $status;
        $user->save();
        return Result::success();
    }


    public function getList(Request $request){
        $query = CashDisabled::query();
        $page = $request->input('page', 1);
        $pageSize = $request->input('pageSize', 10);
        $status = $request->input('status');
        $mobile = $request->input('mobile');
        $query->when($mobile, function($q) use ($mobile) {
            $q->where('mobile', $mobile);
        });
        $query->when($status, function($q) use ($status) {
            $q->where('status',$status);
        });
        $query->orderBy('id','desc');
        $data = $query->latest()->paginate($pageSize, ['*'], 'page', $page);
        return Result::success(new PaginationCollection($data));
    }



}
